import genArchi.ComputeBox;
import genArchi.GenArchiFactory;
import genArchi.GenArchiPackage;
import genArchi.Root;
import utils.Utils;

import completeModel.CompleteModelPackage;


/**
 * 
 * @author Florian Many
 *
 */
public class MGToSolution {

	/**
	 * Attributes
	 */
	private Root root;
	private String filePath = "";
	private String inputExtension = "";
	
	private ComputeBox cb;
		
/**================================ Public Method ============================================================== **/
	
	/**
	 * Constructor
	 */
	public MGToSolution(String path) {
		
		/**/
		initializeString(path);
		
		/**/
		computeSolution();
		
		/**/
		saveSolution();
		
	} // constructor

/**================================ Private Method ============================================================== **/
	
	private void initializeString (String path) {
		
		String[] tokens = path.split("\\.");
		System.out.println ("> Name: " + path);
		System.out.println ("> Length: " + tokens.length);
		
		this.inputExtension = tokens[tokens.length - 1];
		
		for (int i = 0 ; i < tokens.length - 1 ; i++) {
			
			this.filePath = this.filePath + tokens[i];
		}
		
	}
	
	private void computeSolution () {
		
		/**/
		root = GenArchiFactory.eINSTANCE.createRoot();
		/**/
		cb = (ComputeBox)Utils.loadInstance(this.filePath, this.inputExtension, CompleteModelPackage.eINSTANCE).getContents().get(0);
		/**/
		root.getComputeBoxes().add(cb);
		cb.setRoot(root);
		/**/
		cb.compute();
	}
	
	private void saveSolution () {
		
		Utils.saveInstance(this.filePath, "genarchi", this.root, GenArchiPackage.eNS_URI, GenArchiPackage.eINSTANCE);
	}
/**================================== Main ============================================================== **/
	
	public static void main(String[] args) {
		
		for (int i = 0 ; i < args.length ; i++) {

			new MGToSolution (args [i]);
		}

	}


} // MGToSolution
